<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/taglibs.jsp" %>
<%
    response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/page/common/include.jsp"></jsp:include>
<script language="javascript" type="text/javascript">

$(document).ready(function(){
	
	/** 初始化查询面板 */
	$("#searchPanel").panel({
		collapsible:true,
		border:false,
		closable:true
	});
	
	/** 初始化编辑窗口 */
	$("#editDiv").window({
		title:'修改业务系统',
		width:400,
		height:300,
		modal:true,
		closed:true,
		minimizable:false,
		maximizable:false
	});
	
	/** 初始化查看窗口 */
	$("#viewDiv").window({
		title:'查看业务系统',
		width:600,
		height:300,
		modal:true,
		closed:true,
		minimizable:false,
		maximizable:false
	});
	
	/** 初始化业务系统Grid Table */
	$("#gridTable").datagrid({
		title:"业务系统列表",
		url:'<%=request.getContextPath()%>/systemInfo/systemInfoAction!listSystemInfo.do',
		singleSelect:true,
		rownumbers:true,
		striped:true,
		fitColumns:true,
		toolbar:"#toolbar",
		pagination:true,
		columns:[[
       		{field:'sysCode',title:'系统编号',width:100},
          	{field:'sysName',title:'系统名称',width:100},
          	{field:'sysAbbr',title:'系统别名',width:100,align:'right'},
          	{field:'sysUrl',title:'链接地址',width:200,align:'right',formatter:sysUrlFormatter},
          	{field:'orderIndex',title:'排序号',width:100,align:'right'},
          	{field:'sysStatusName',title:'有效状态',width:100,align:'right',formatter:statusFormat},
          	{field:'recordCrtTime',title:'操作',width:100,align:'center',formatter:operate},
          	{field:'version',title:'版本号',hidden:true}
     	]],
     	onClickRow:function(rowIndex,rowData){
     		
     	},
     	onBeforeLoad:function(){
     		disableLinkButton();
     	},
		onLoadSuccess:function(){
			enableLinkButton();
			$(".loan_ct_view_button").linkbutton({
				plain:false
			});
			$(".sys_url_tooltip").tooltip();
		}
	});
});

function sysUrlFormatter(value,rowData){
	return "<span class='sys_url_tooltip' title='"+value+"'>"+value+"</span>";
}

/**
 * 格式化业务系统状态
 */
function statusFormat(value,rowData){
	if(rowData.sysStatus == '0'){
		return "<span style='color:green;'>"+value+"</span>";
	}else if(rowData.sysStatus == '1'){
		return "<span style='color:red;'>"+value+"</span>";
	}
}

/**
 * 修改业务系统状态
 */
function operate(value,rowData){
	var title = '';
	if(rowData.sysStatus == '0'){
		title = '停用';
	}else if(rowData.sysStatus == '1'){
		title = '启用';
	}
	return "<a href='javascript:void(0)' onclick='changeStatus(\""+rowData.sysStatus+"\",\""+rowData.sysCode+"\",\""+rowData.version+"\")' class='loan_ct_view_button'>"+title+"</a>";
}

/**
 * 修改业务系统状态
 */
function changeStatus(sysStatus,sysCode,version){
	var title = '';
	if(sysStatus == '0'){
		title = '你确定要停用该业务系统吗?';
		sysStatus = '1';
	}else if(sysStatus == '1'){
		title = '你确定要启用该业务系统吗?';
		sysStatus = '0';
	}
	$.messager.confirm('操作提示', title, function(r){
		if (r){
			$.ajax({
				url : '<%=request.getContextPath()%>/systemInfo/systemInfoAction!changeSystemInfoStatus.do',
				type : 'post',
				dataType : 'text',
				cache : false,
				data : {
					sysCode : sysCode,
					sysStatus : sysStatus,
					version : version
				},
				success : function(data) {
					var j = JSON.parse(data);
					if (j.result = 'success') {
						$.messager.alert('操作结果', '状态修改成功！','info');
						$("#gridTable").datagrid("reload");
					} else {
						$.messager.alert('操作结果', j.msg,'error');
					}
				}
			});
		}
	});
}

/**
 * 初始化修改窗口
 */
function initEditWindow(data){
   return $("#editDiv").window({
		onBeforeOpen:function(){
			$("#sysCode_edit").attr("disabled","disabled");
			resetFormValue(data);
		},
		onBeforeClose:function(){
			resetFormValue(null);
		}
	});
}

/**
 * 修改业务系统
 */
function edit(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要修改的业务系统！");
		return;
	}
	$.ajax({
		url : '<%=request.getContextPath()%>/systemInfo/systemInfoAction!initEditSystemInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCode : rowData.sysCode,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				var editSystemInfoDiv = initEditWindow(JSON.parse(j.msg));
				editSystemInfoDiv.window("open");
			} else {
				$.messager.alert('通知', j.msg,'warn');
				$("#gridTable").datagrid("reload");
			}
		}
	});
}

/**
 * 删除业务系统
 */
function remove(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要修改的业务系统！");
		return;
	}
	messageConfirm("操作提示",'你确定要删除所选的业务系统吗?',removeCallback);
}

/**
 * 删除操作回调函数
 */
function removeCallback(){
	var rowData = $('#gridTable').datagrid('getSelected');
	$.ajax({
		url : '<%=request.getContextPath()%>/systemInfo/systemInfoAction!deleteSystemInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCodes : rowData.sysCode
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				$.messager.alert('操作结果', '系统信息删除成功！','info');
				$("#gridTable").datagrid("reload");
			} else {
				$.messager.alert('操作结果', j.msg,'error');
			}
		}
	});
}

/**
 * 	清空表单内容
 */
function resetFormValue(rowData){
	if(rowData == null){
		 rowData = {sysCode:'',sysName:'',sysAbbr:'',sysUrl:'',orderIndex:'',version:'0'};
	}
	$("#sysCode_edit").val(rowData.sysCode);
	$("#sysName_edit").val(rowData.sysName);
	$("#sysAbbr_edit").val(rowData.sysAbbr);
	$("#sysUrl_edit").val(rowData.sysUrl);
	$("#orderIndex_edit").val(rowData.orderIndex);
	$("#version_edit").val(rowData.version)
}

/**
 * 获取表单的值
 */
function getFormValue() {
	var sysInfo = {
		sysCode : $("#sysCode_edit").val(),
		sysName : $("#sysName_edit").val(),
		sysAbbr : $("#sysAbbr_edit").val(),
		sysUrl : $("#sysUrl_edit").val(),
		orderIndex : $("#orderIndex_edit").val(),
		version : $("#version_edit").val()
	};
	return sysInfo;
}

/**
 * 修改页面提交
 */
function editWindowSubmit() {
	$.ajax({
		url : '<%=request.getContextPath()%>/systemInfo/systemInfoAction!editSystemInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysInfo : JSON.stringify(getFormValue())
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				$.messager.alert('操作结果', '业务系统修改成功！', 'info');
				editWindowClose();
				$("#gridTable").datagrid("reload");
			} else {
				$.messager.alert('操作结果', j.msg, 'error');
			}
		}
	});
}

/**
 * 关闭修改页面
 */
function editWindowClose() {
	$("#editDiv").window("close");
}

/**
 * 验证业务系统编号是否存在
 */
function checkSysCode(obj){
	var sysCode = $.trim(obj.val());
	obj.val($.trim(obj.val()));
	if(sysCode != ''){
		$.ajax({
			url : '<%=request.getContextPath()%>/systemInfo/systemInfoAction!checkSysCode.do',
			type : 'post',
			dataType : 'text',
			cache : false,
			data : {
				sysCode : sysCode
			},
			success : function(data) {
				var j = JSON.parse(data);
				if (j.result == 'fail') {
					$.messager.alert('操作结果', j.msg, 'error');
					obj.val('');
				} 
			}
		});
	}
}

/**
 * 查询业务系统
 */
function sysInfoSearch(){
	$("#sysCode_search").val($.trim($("#sysCode_search").val()));
	$("#sysName_search").val($.trim($("#sysName_search").val()));
	$("#gridTable").datagrid("load",{
		sysCode:$("#sysCode_search").val(),
		sysName:$("#sysName_search").val()
	});
}

/**
 * 清空业务系统查询条件
 */
function clearSearchCriteria(){
	goToPage('<%=request.getContextPath()%>/systemInfo/systemInfoAction!initSystemInfo.do');
}

/**
 * 查看
 */
function view(){
	var rowData = $('#gridTable').datagrid('getSelected');
	if(rowData == null){
		messageAlertWarning("操作提示","请选择要查看的用户信息！");
		return;
	}
	$.ajax({
		url : '<%=request.getContextPath()%>/systemInfo/systemInfoAction!initEditSystemInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			sysCode : rowData.sysCode,
			version : rowData.version
		},
		success : function(data) {
			var j = JSON.parse(data);
			if (j.result = 'success') {
				var viewSystemInfoDiv = initViewWindow(JSON.parse(j.msg));
				viewSystemInfoDiv.window("open");
			} else {
				$.messager.alert('通知', j.msg,'warn');
				$("#gridTable").datagrid("reload");
			}
		}
	});
}

/**
 * 初始化查看窗口
 */
function initViewWindow(systemInfo){
	   return $("#viewDiv").window({
			onBeforeOpen:function(){
				$("#sysCode_view").text(systemInfo.sysCode);
				$("#sysName_view").text(systemInfo.sysName);
				$("#sysAbbr_view").text(systemInfo.sysAbbr);
				$("#sysUrl_view").text(systemInfo.sysUrl);
				$("#orderIndex_view").text(systemInfo.orderIndex);
				var systemStatusNameFormat = "";
				if(systemInfo.sysStatus == '0'){
					systemStatusNameFormat = "<span style='color:green;'>"+systemInfo.sysStatusName+"</span>";
				}else if(systemInfo.sysStatus == '1'){
					systemStatusNameFormat = "<span style='color:red;'>"+systemInfo.sysStatusName+"</span>";
				}
				$("#sysStatusName_view").html(systemStatusNameFormat);
				$("#recordCrtOperLoginName_view").text(systemInfo.recordCrtOperLoginName);
				$("#recordCrtTime_view").text(systemInfo.recordCrtTime);
				$("#recordUpdOperLoginName_view").text(systemInfo.recordUpdOperLoginName);
				$("#recordUpdTime_view").text(systemInfo.recordUpdTime);
				$("#version_view").text(systemInfo.version);
			},
			onBeforeClose:function(){
				
			}
		});
}

/**
 * 关闭查看窗口
 */
function viewWindowClose() {
	$("#viewDiv").window("close");
}
</script>
</head>

<body style="background: white;" >
	<!-- 查询面板 -->
	<div id="searchPanel" style="width:'100%';height:95px;padding:20px;" align="center">
		<table>
			<tr>
				<td>系统编号：<input id="sysCode_search" type="text" style="width:100px"/></td>
				<td>系统名称：<input id="sysName_search" type="text" style="width:100px"/></td>
			</tr>
			<tr>
				<td colspan="2" align="center" style="padding-top: 10px">
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="sysInfoSearch()">查询</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" onclick="clearSearchCriteria()">清空</a>
				</td>
			</tr>
		</table>
	</div>
	
	<!-- 数据Table -->
	<table id="gridTable" style="width:'90%';height:'100%'">
	</table>
	
	<!-- 工具栏 -->
	<div id="toolbar" style="padding:5px;">
		<a href="javascript:void(0)" id="editBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" onclick="edit()">修改</a>
		<a href="javascript:void(0)" id="removeBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="remove()">删除</a>
		<a href="javascript:void(0)" id="viewBtn" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="view()">查看</a>
	</div>
	
	<!-- 编辑窗口 -->
	<div id="editDiv" style="padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;" align="center">
		    	<table>
		    		<s:hidden name="version_edit" value="0"/>
		    		<tr>
		    			<td>系统编号:</td>
		    			<td>
		    				<input id="sysCode_edit"  type="text" onblur="checkSysCode($(this))" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>系统名称:</td>
		    			<td><input id="sysName_edit"  type="text" /></td>
		    		</tr>
		    		<tr>
		    			<td>系统别名:</td>
		    			<td>
		    				<input id="sysAbbr_edit"  type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>链接地址:</td>
		    			<td>
		    				<input id="sysUrl_edit"  type="text" />
		    			</td>
		    		</tr>
		    		<tr>
		    			<td>排序号:</td>
		    			<td>
		    				<input id="orderIndex_edit" type="text"/>
		    			</td>
		    		</tr>
		    	</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="editWindowSubmit()">提交</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="editWindowClose()">取消</a>
			</div>
		</div>
	</div>
	
	<!-- 查看窗口 -->
	<div id="viewDiv" style="padding:10px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;" align="center">
		    	<table class="view_table">
		    		<tr>
		    			<th>系统编号</th>
		    			<td id="sysCode_view"/>
		    			<th>系统名称</th>
		    			<td id="sysName_view"/>
		    		</tr>
		    		<tr>
		    			<th>系统别名</th>
		    			<td id="sysAbbr_view"/>
		    			<th>链接地址</th>
		    			<td id="sysUrl_view"/>
		    		</tr>
		    		<tr>
		    			<th>排序号</th>
		    			<td id="orderIndex_view"/>
		    			<th>有效状态</th>
		    			<td id="sysStatusName_view"/>
		    		</tr>
		    		<tr>
		    			<th>记录创建人</th>
		    			<td id="recordCrtOperLoginName_view" />
		    			<th>记录创建时间</th>
		    			<td id="recordCrtTime_view"/>
		    		</tr>
		    		<tr>
		    			<th>记录更新人</th>
		    			<td id="recordUpdOperLoginName_view"/>
		    			<th>记录更新时间</th>
		    			<td id="recordUpdTime_view"/>
		    		</tr>
		    		<tr>
		    			<th>版本号</th>
		    			<td id="version_view"/>
		    			<th></th>
		    			<td></td>
		    		</tr>
		    	</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="viewWindowClose()">关闭</a>
			</div>
		</div>
	</div>
</body>
</html>